package query

type Match struct {
	Key                string      `json:"-"`
	Query              interface{} `json:"query"`
	Fuzziness          string      `json:"fuzziness,omitempty"`
	MinimumShouldMatch string      `json:"minimum_should_match,omitempty"`
	Operator           string      `json:"operator,omitempty"`
}

func (g *Match) Empty() bool { return g == nil || g.Key == "" || IsAnyEmpty(g.Query) }

func (g *Match) Map() Map {
	vm := Map{
		"query": g.Query,
	}
	if g.Fuzziness != "" {
		vm["fuzziness"] = g.Fuzziness
	}
	if g.MinimumShouldMatch != "" {
		vm["minimum_should_match"] = g.MinimumShouldMatch
	}
	if g.Operator != "" {
		vm["operator"] = g.Operator
	}

	m := Map{"match": Map{g.Key: vm}}

	return m
}
